var $,tab,dataStr,layer;
layui.extend({
	"bodyTab" : "/js/pages/bodyTab"
})
layui.use(['bodyTab','form','element','layer','jquery'],function(){
	var form = layui.form,
		element = layui.element;
		$ = layui.$;
    	layer = parent.layer === undefined ? layui.layer : top.layer;

    //获取登录的用户信息
	function getUserInfo( callback){
		$.ajaxSettings.async = false;
		$.get("/adminUser/getUserInfo",function( res){
			if( res.code == 200){
				callback( res.data);
			}else if( res.code == 304){
				top.layer.confirm( "用户尚未登录，点击跳转到登录页面", function(){
					window.location.href = "/pages/login.html";
				});
			}else{
				top.layer.alert( res.msg);
			}
		});
	}

	var userInfo= {};
	getUserInfo( function( data){
		userInfo = data;
	});

	//将用户信息缓存起来
	window.sessionStorage.setItem( "userInfo", JSON.stringify( userInfo));

	var headImg = userInfo.headImg ? userInfo.headImg : "/images/face2.jpg";
	//设置右上角的用户信息
	$("#adminName").html( userInfo.prenom + " " + userInfo.nom);
	$("#adminHeadImg").attr( "src", headImg);
	//设置菜单栏上面的用户信息
	$("#adminNameInMenu").html( userInfo.role.roleName + ":" + userInfo.prenom + " " + userInfo.nom);
	$("#adminHeadImgInMenu").attr( "src", headImg);

	//用户未修改过密码-锁屏打开密码修改页面
	if( userInfo.passwordStatus == "SYSTEM"){
		layer.open({
			title : "修改密码",
			type : 2,
			content : '/pages/user/changePassword.html',
			area: [ 600 + 'px', 420 + 'px'],
			closeBtn : 0,
			shade : 0.9,
			success : function(){
			}
		})
	}

	$(document).on('keydown', function(event) {
		var event = event || window.event;
		if(event.keyCode == 13) {
			$("#unlock").click();
		}
	});

	//退出
	$("#signOutBtn").click(function(){
		$.post("/adminUser/logout",function( res){
			if( res.code == 200){
				window.sessionStorage.removeItem("userInfo");
				top.layer.msg( res.msg);
				setTimeout( function () {
					window.location.href = "/pages/login.html";
				}, 1 * 1000);
			}else{
				top.layer.msg( res.msg);
			}
		});

	})
})
